﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraTreeList.StyleFormatConditions;
using DXApplicationTangche.UC.款式异常;

namespace WindowsFormsApplication1
{
    public partial class Form1 : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public Form1()
        {
            InitializeComponent();
            InitializeControlData();
        }



        private void InitializeControlData()
        {

            StyleFormatCondition styleFormatCondition1 = new StyleFormatCondition();
            StyleFormatCondition styleFormatCondition2 = new StyleFormatCondition();
            StyleFormatCondition styleFormatCondition3 = new StyleFormatCondition();
            StyleFormatCondition styleFormatCondition4 = new StyleFormatCondition();
            StyleFormatCondition styleFormatCondition5 = new StyleFormatCondition();
            StyleFormatCondition styleFormatCondition6 = new StyleFormatCondition();

            // 0 已处理,1 延迟处理,2 首次未处理, 3 再次未处理

            styleFormatCondition1.Appearance.ForeColor = System.Drawing.Color.Gray;  //0  要出現[灰色],狀態為已處理
            styleFormatCondition1.Appearance.Options.UseForeColor = true;
            styleFormatCondition1.ApplyToRow = true;
            styleFormatCondition1.Column = this.colState;
            styleFormatCondition1.Condition = DevExpress.XtraGrid.FormatConditionEnum.Equal;
            styleFormatCondition1.Value1 = 0;

            //styleFormatCondition2.Appearance.Font = new System.Drawing.Font("Segoe UI", 9F);
            styleFormatCondition2.Appearance.ForeColor = System.Drawing.Color.Red;    // 1 要出現[黑色],狀態為延迟处理
            //styleFormatCondition2.Appearance.Options.UseFont = true;
            styleFormatCondition2.Appearance.Options.UseForeColor = true;
            styleFormatCondition2.ApplyToRow = true;
            styleFormatCondition2.Column = this.colState;
            styleFormatCondition2.Condition = DevExpress.XtraGrid.FormatConditionEnum.Equal;
            styleFormatCondition2.Value1 = 1;

            //styleFormatCondition3.Appearance.Font = new System.Drawing.Font("Segoe UI", 9F);
            styleFormatCondition3.Appearance.ForeColor = System.Drawing.Color.Green;             //   要出現[綠色],狀態為 首次未处理
            //styleFormatCondition3.Appearance.Options.UseFont = true;
            styleFormatCondition3.Appearance.Options.UseForeColor = true;
            styleFormatCondition3.ApplyToRow = true;
            styleFormatCondition3.Column = this.colState;
            styleFormatCondition3.Condition = DevExpress.XtraGrid.FormatConditionEnum.Equal;
            styleFormatCondition3.Value1 = 2;

            //styleFormatCondition4.Appearance.Font = new System.Drawing.Font("Segoe UI", 9F);
            styleFormatCondition4.Appearance.ForeColor = System.Drawing.Color.Black;             //   要出現[黑色],狀態為再次未处理
            //styleFormatCondition4.Appearance.Options.UseFont = true;
            styleFormatCondition4.Appearance.Options.UseForeColor = true;
            styleFormatCondition4.ApplyToRow = true;
            styleFormatCondition4.Column = this.colState;
            styleFormatCondition4.Condition = DevExpress.XtraGrid.FormatConditionEnum.Equal;
            styleFormatCondition4.Value1 = 3;


            styleFormatCondition5.Appearance.ForeColor = System.Drawing.Color.Orange;             // 狀態為延遲未聯絡
            styleFormatCondition5.Appearance.Options.UseForeColor = true;
            styleFormatCondition5.ApplyToRow = true;
            styleFormatCondition5.Column = this.colState;
            styleFormatCondition5.Condition = DevExpress.XtraGrid.FormatConditionEnum.Equal;
            styleFormatCondition5.Value1 = 4;


            styleFormatCondition6.Appearance.ForeColor = System.Drawing.Color.Yellow;             // 狀態為正常聯絡
            styleFormatCondition6.Appearance.Options.UseForeColor = true;
            styleFormatCondition6.ApplyToRow = true;
            styleFormatCondition6.Column = this.colState;
            styleFormatCondition6.Condition = DevExpress.XtraGrid.FormatConditionEnum.Equal;
            styleFormatCondition6.Value1 = 5;

            this.treeList1.FormatConditions.Clear();
            this.treeList1.FormatConditions.AddRange(new StyleFormatCondition[] {
            styleFormatCondition1,
            styleFormatCondition2,
            styleFormatCondition3,
            styleFormatCondition4,
            styleFormatCondition5,
            styleFormatCondition6});
        }

        private void DataBind()
        {
            var tempList = new List<temp>();

            for (int i = 1; i < 100; i++)
            {
                tempList.Add(new temp() { Id = i, ParentId = getParenId(i), State = i % 6 });
            }

            treeList1.DataSource = tempList;
        }

        private int getParenId(int current)
        {
            Random r = new Random();
            return r.Next(0, current - 1);
        }


        private class temp
        {
            private int _id;
            [System.ComponentModel.Bindable(true)]
            public int Id
            {
                get { return _id; }
                set { _id = value; }
            }


            private int parentId;
            [System.ComponentModel.Bindable(true)]
            public int ParentId
            {
                get { return parentId; }
                set { parentId = value; }
            }


            [System.ComponentModel.Bindable(true)]
            public string Name
            {
                get
                {
                    string value = string.Empty;
                    switch (this.State)
                    {
                        case 0:
                            value = "Gray";
                            break;
                        case 1:
                            value = "Red";
                            break;
                        case 2:
                            value = "Green";
                            break;
                        case 3:
                            value = "Black";
                            break;
                        case 4:
                            value = "Orange";
                            break;
                        case 5:
                            value = "Yellow";
                            break;
                        default:
                            break;
                    }
                    return value;
                }
            }

            private int _state;
            [System.ComponentModel.Bindable(true)]
            public int State
            {
                get { return _state; }
                set { _state = value; }
            }

        }


        private void Form1_Load(object sender, EventArgs e)
        {
            DataBind();
        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            MessageBox.Show(门店下单选款式Model.getSTYLE_CD());
        }
    }
}
